import { Injectable } from '@angular/core'
import { HttpClientService } from 'src/app/common/httpClient/http'
import { CommonUtil } from 'src/app/common/utils/common.util'

@Injectable({
  providedIn: 'root'
})
export class DiscoverService {
  start = ''
  end = ''
  reqdata = {
    pager: { Start: 0, Limit: 10 },
    filter: {
      Lambda: '',
      Navigations: []
    },
    sorters: [{ Property: 'item=>item.UpdateTime', Direction: 'Descending' }]
  }

  constructor(private http: HttpClientService, private utils: CommonUtil) {
    this.start = this.utils.time2UTC(new Date())
    this.end = this.utils.time2UTC(new Date())
  }

  getList(Start, callback, errorBack?) {
    let lambda = `item=>item.Enable&&item.Start<=${this.start}&&item.end>=${this.end}`
    this.reqdata.pager.Start = Start
    this.reqdata.filter.Lambda = lambda
    this.http.post(this.reqdata, '/House1/Json/FoundService.svc/Query', callback, errorBack)
  }
}
